home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / delphi1 / lesson1 / test.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1996-07-07  |  1.3 KB  |  63 lines

  1. unit Test;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Edit1: TEdit;
  12.     Button1: TButton;
  13.     procedure Button1Click(Sender: TObject);
  14.   private
  15.     { Private declarations }
  16.   public
  17.     { Public declarations }
  18.   end;
  19.  
  20. var
  21.   Form1: TForm1;
  22.  
  23. implementation
  24.  
  25. {$R *.DFM}
  26.  
  27. procedure ShowMessage(inputText : string );
  28. { Display a message with a '!' (mtInformation and OK button }
  29. begin
  30.   MessageDlg(inputText, mtInformation,[mbOK] , 0);
  31. end;
  32.  
  33. function MakeMessage(msg: string): string;
  34. { Return a string including msg parameter }
  35. begin
  36.   MakeMessage := 'You entered: ' + msg + '!' ;
  37. end;
  38.  
  39.  
  40. procedure TForm1.Button1Click(Sender: TObject);
  41. { This procedure examines the Edit1 text box. If it
  42. contains the text, 'Hello world', the user is congratulated.
  43. Otherwise, the user is asked to try agan. }
  44. Const
  45.      FormName = 'Test Form';
  46. Var
  47.      SomeText : string;
  48.      a_message   : string;
  49. begin
  50.      SomeText := Edit1.Text;
  51.      if SomeText = 'Hello world' Then
  52.         Form1.Caption := FormName + ' Success!'
  53.      else
  54.      begin
  55.           Edit1.Text := 'Please try again';
  56.           Form1.Caption := FormName + ' Failure!'
  57.      end;
  58.      a_message := MakeMessage(SomeText);
  59.      ShowMessage(a_message);
  60. end;
  61.  
  62. end.
  63.